﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Processes.Orden;
using Model.Orden;
using System.Web.Security;
namespace Interfaces.Orden
{
    public partial class Inicio : System.Web.UI.Page
    {
        string res;

        GestorOrden gestorOrden;
        Order orden = new Order();
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.Identity.IsAuthenticated)
                FormsAuthentication.RedirectToLoginPage();
            LabelError.Visible = false;
                if (Session["BuscarMaster"] != null && Session["BuscarMaster"].ToString().Equals("~/MasterPages/Presidenta.Master"))
                {
                    
                    try
                    {
                        gestorOrden = new GestorOrden();
                        orden = gestorOrden.BuscarOrdenSinAprobar();

                        if (orden != null)
                        {
                            Label1.Visible = true;
                            Label2.Visible = true;
                            LinkButton1.Visible = true;
                            Session["OrdenVer"] = orden;
                        }
                        else
                        {
                            Label1.Text = "No hay ninguna novedad";
                            Label1.Visible = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        LabelError.Visible = true;
                        LabelError.Text += ex.Message;
                    }
                }
           
            
        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["BuscarMaster"] != null)
            {
                res = (string)Session["BuscarMaster"];
                this.MasterPageFile = res;
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            
            if (Session["OrdenVer"] != null)
            {
                orden = (Order)Session["OrdenVer"];
                Response.Redirect("Ver.aspx?Nro=" + orden.Nro + "&Fecha=" + orden.Fecha + " &FechaUltimaModificacion=" + orden.FechaUltimaModificacion);
            }
        }
    }
}